﻿namespace 对象初始化器
{
    internal class Program
    {
        static void Main(string[] args)
        {

            Person person = new Person()
            {
                Name = "Test",
                Age = 1,
                Sex = "男"
            };

            Console.WriteLine(person.ToString());

            List<Person> list = new List<Person>() 
            { 
                new Person() {Name = "Test", Age = 1,Sex="男"},
                new Person() {Name = "Test2", Age = 2,Sex="男"},
                new Person() {Name = "Test3", Age = 3,Sex="男"},
                new Person() {Name = "Test4", Age = 4,Sex="男"}
            };

            list.ForEach(person =>
            {
                Console.WriteLine(person.ToString());
            });

            


            Console.WriteLine("Hello, World!");
        }
    }


    #region 类的对象的初始化器
    internal class Person
    {
        public string Name { get; set; }

        public int Age { get; set; }

        public string Sex { get; set;}

        public override string? ToString()
        {
            return $"Name:{Name},Age:{Age},Sex:{Sex}";
        }
    }

    #endregion
}
